package com.shop2cn.iapi.livebuyer.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.app.liveseller.parameter.CreateSellerLiveBean;
import com.shop2cn.iapi.livebuyer.parameter.*;
import com.shop2cn.iapi.livebuyer.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.LiveRoom;
import com.ymttest.utils.TestDataManager;
/**
*结束云通讯群组
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CleanInvalidGroup{
	private static CleanInvalidGroupBean cleaninvalidgroupBean;
	private static CleanInvalidGroupCall cleaninvalidgroupCall;
	private static int sellerId ;
	private static String token ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("结束云通讯群组");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		cleaninvalidgroupBean=new CleanInvalidGroupBean();
		cleaninvalidgroupCall=new CleanInvalidGroupCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cleaninvalidgroupCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CleanInvalidGroup_001() {
		Logger.start(true,"action-1结束云通讯群组成功");
		try {
			String groupId = LiveRoomShop2cnCallService.CreateGroup("AT"+TestDataManager.getRandomNumToHex(55), sellerId);
			CreateSellerLiveBean cbean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			cbean.getLiveDto().setGroupId(groupId);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(cbean,sellerId);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnCallService.SendMsg(groupId, "test1");
			String code=LiveRoomShop2cnCallService.SendMsg(groupId, "test2").getString("code");
			Logger.verifyEquals("200", code, "发送成功");
			Thread.sleep(1000);
			LiveRoomShop2cnCallService.AutoCloseLiveRoomByUserId(sellerId);
			Thread.sleep(1000);
			cleaninvalidgroupCall.setData(cleaninvalidgroupBean);
			cleaninvalidgroupCall.callService();			
			Thread.sleep(1000);
			code=LiveRoomShop2cnCallService.SendMsg(groupId, "test2").getString("code");
			Logger.verifyEquals("400", code, "发送失败");
			//{"code":400,"message":"this group does not exist","serverTime":"2020-01-19 15:26:46","data":null}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CleanInvalidGroup_002() {
		Logger.start(true,"正常结束直播-结束云通讯群组成功");
		try {
			String groupId = LiveRoomShop2cnCallService.CreateGroup("AT"+TestDataManager.getRandomNumToHex(55), sellerId);
			CreateSellerLiveBean cbean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			cbean.getLiveDto().setGroupId(groupId);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(cbean,sellerId);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnCallService.SendMsg(groupId, "test1");
			String code=LiveRoomShop2cnCallService.SendMsg(groupId, "test2").getString("code");
			Logger.verifyEquals("200", code, "发送成功");
			Thread.sleep(1000);
			LiveRoomShop2cnCallService.CloseSellerLive(createlive.getId(), createlive.getUserId(), 9);
			Thread.sleep(1000);
			cleaninvalidgroupCall.setData(cleaninvalidgroupBean);
			cleaninvalidgroupCall.callService();			
			Thread.sleep(1000);
			code=LiveRoomShop2cnCallService.SendMsg(groupId, "test2").getString("code");
			Logger.verifyEquals("400", code, "发送失败");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CleanInvalidGroup_003() {
		Logger.start(true,"直播未结束-结束云通讯群组失败");
		try {
			String groupId = LiveRoomShop2cnCallService.CreateGroup("AT"+TestDataManager.getRandomNumToHex(55), sellerId);
			CreateSellerLiveBean cbean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			cbean.getLiveDto().setGroupId(groupId);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(cbean,sellerId);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnCallService.SendMsg(groupId, "test1");
			String code=LiveRoomShop2cnCallService.SendMsg(groupId, "test2").getString("code");
			Logger.verifyEquals("200", code, "发送成功");
			Thread.sleep(1000);
//			LiveRoomShop2cnCallService.CloseSellerLive(createlive.getId(), createlive.getUserId(), 9);
			Thread.sleep(1000);
			cleaninvalidgroupCall.setData(cleaninvalidgroupBean);
			cleaninvalidgroupCall.callService();			
			Thread.sleep(1000);
			code=LiveRoomShop2cnCallService.SendMsg(groupId, "test2").getString("code");
			Logger.verifyEquals("200", code, "发送成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}